package psd.model.Prolog.Converters;

import org.eclipse.jdt.core.dom.Annotation;
import org.eclipse.jdt.core.dom.IMethodBinding;
import org.eclipse.jdt.core.dom.MemberValuePair;

import psd.model.IConverter;
import psd.model.Prolog.FactGenerationToolbox;
import psd.model.Prolog.PrologConverter;


public class PrologMemberValuePairConverter extends PrologConverter implements
		IConverter<MemberValuePair> {

	public PrologMemberValuePairConverter(FactGenerationToolbox toolbox) {
		super(toolbox);
	}

	@Override
	public boolean convert(MemberValuePair node) {
		Annotation annotation = (Annotation) node.getParent();
		IMethodBinding methods[] = annotation.resolveTypeBinding()
				.getDeclaredMethods();
		String binding = null;
		for (int i = 0; i < methods.length; i++) {
			if (methods[i].getName().equals(node.getName().getIdentifier())) {
				binding = idResolver.getID(methods[i]);
			}
		}

		String id = idResolver.getID(node);
		checkAndGenComments(node, id);
		writer.writeFact("memberValueT", new String[] { id, getParentId(node),
				binding, idResolver.getID(node.getValue()), this.getFilePath(node), this.getLineNumber(node) });
		return true;
	}

}
